package org.zyj.io.example.case8;

import io.netty.bootstrap.Bootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.SocketChannel;
import io.netty.channel.socket.nio.NioSocketChannel;

/**
 * 描述
 *
 * @author zhouyijin
 * @date 2022-01-14 16:23:09
 */
class ByteToLongClient {

    public static void main(String[] args) throws InterruptedException {
        final EventLoopGroup eventExecutors = new NioEventLoopGroup();
        try {
            final Bootstrap bootstrap = new Bootstrap();
            //
            bootstrap.group(eventExecutors)//
                    .channel(NioSocketChannel.class)//
                    .handler(new ChannelInitializer<SocketChannel>() { //
                        @Override
                        protected void initChannel(SocketChannel ch) throws Exception {
                            ch.pipeline()//
                                    .addLast(new LongToByteEncoder())//
//                                    .addLast(new ByteToLongDecoder())//
                                    .addLast(new ByteToLongDecoder2())//
                                    .addLast(new ClientHandler());//
                        }
                    });
            System.out.println("client setup done");

            final ChannelFuture channelFuture = bootstrap.connect("127.0.0.1", 9998).sync();//

            channelFuture.channel().closeFuture().sync();
        } finally {
            eventExecutors.shutdownGracefully();
        }


    }

}
